<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>轮播图</title>

    <style>
        * {
            padding: 0;
            margin: 0;
        }

        img {
            width: 100%;
        }

        #banner {
            position: relative;
            width: 400px;
            height: auto;
            margin: 20px auto;
            padding: 30px;
            text-align: center;
            background: #eed0bb;
        }

        #banner .list {
            position: relative;
            overflow: hidden;
            padding: 10px;
            height: 561px;
        }

        #banner .list li {
            position: absolute;
            width: 400px;
            padding: 10px;
            background: #fff;
            box-sizing: border-box;
            opacity: 0;
            filter: alpha(opacity=0);
            top: 0;
            left: 0;
        }

        #banner .list .current {
            opacity: 1;
            filter: alpha(opacity=100);
        }


        #banner .count {
            position: absolute;
            left: 246px;
            bottom: 40px;
        }

        #banner .count li {
            float: left;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: rgb(255, 200, 47);
            margin-left: 5px;
            color: #fff;
            opacity: 0.7;
            filter: alpha(opacity=70);
            list-style: none;
            cursor: pointer;
        }

        #banner .count .current {
            color: #fff;
            opacity: 1;
            filter: alpha(opacity=100);
            font-weight: 700;
            background: #f60;
        }
    </style>

    <script>
        function change(list, index) {
            for (var i = 0; i < list.length; i++) {
                list[i].className = '';
            }
            list[index].className = "current";
        }


        window.onload = function () {
            var oBanner = document.getElementById("banner");
            var aList = document.getElementsByClassName('list')[0].getElementsByTagName('li');
            var aCount = document.getElementsByClassName('count')[0].getElementsByTagName('li');
            var mintor = 0;
            var timer = play = null;
            var bOrder = true;
            var i = 0;

            for (i = 0; i < aCount.length; i++) {
                aCount[i].index = i;
                aCount[i].onmouseover = function () {

                    show(this.index);

                    // change(aCount, this.index);
                    // change(aList, this.index);
                }
            }

            oBanner.onmouseover = function () {
                clearInterval(play);
            }

            oBanner.onmouseout = function () {
                autoPlay();
            }

            autoPlay();

            function autoPlay() {
                play = setInterval(() => {
                    bOrder ? mintor++ : mintor--;
                    mintor >= aList.length && (mintor = aList.length - 2, bOrder = false);
                    mintor <= 0 && (mintor = 0, bOrder = true);
                    show(mintor);
                }, 3000);
            }

            function show(a) {
                mintor = a;
                var alpha = 0;
                for (i = 0; i < aList.length; i++) {
                    aList[i].style.opacity = 0;
                    aList[i].style.filter = "alpha(opacity=0)";
                }
                change(aCount, mintor);
                clearInterval(timer);
                for (i = 0; i < aList.length; i++) {
                    aList[i].className = '';
                }

                timer = setInterval(() => {
                    alpha += 2;
                    alpha > 100 && (alpha = 100);
                    aList[mintor].style.opacity = alpha / 100;
                    aList[mintor].style.filter = "alpha(opacity=" + alpha + ")";
                    alpha == 100 && clearInterval(timer);
                }, 20);
            }
        }
    </script>
</head>

<body>
    <div id="banner">
        <div class="list">
            <li class="current"><img src="../20.2.21/瀑布流/img/1.jpg" alt=""></li>
            <li><img src="../20.2.21/瀑布流/img/2.jpg" alt=""></li>
            <li><img src="../20.2.21/瀑布流/img/3.jpg" alt=""></li>
            <li><img src="../20.2.21/瀑布流/img/4.jpg" alt=""></li>
            <li><img src="../20.2.21/瀑布流/img/5.jpg" alt=""></li>
            <li><img src="../20.2.21/瀑布流/img/10.jpg" alt=""></li>
            <li><img src="../20.2.21/瀑布流/img/16.jpg" alt=""></li>
        </div>
        <div class="count">
            <ul>
                <li class="current">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
                <li>6</li>
                <li>7</li>
            </ul>
        </div>
    </div>
</body>

</html>